<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>礼包管理</title>
<link rel="stylesheet" type="text/css" media="screen"
	href="../../global/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen"
	href="../../global/css/dataTables.bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen"
	href="../../global/layui/css/layui.css">
</head>
<body>
	<div>
		<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
			<header style="height: 100%">
				<div align="left">
					<table style="width: 100%">
						<tr>
							<td>
								<form class="form-inline" onsubmit="return false">
									<div class="form-group">
										商品: <input id="name" type="text" class="form-control"
											placeholder="商品名称"> 购买条件: <select id="befor">
											<option value="">请选择</option>
											<option value="0">会员</option>
											<option value="1">导购</option>
											<option value="2">讲师</option>
											<option value="3">经理</option>
											<option value="4">商家</option>
										</select> 购买后身份: <select id="after">
											<option value="">请选择</option>
											<option value="0">会员</option>
											<option value="1">导购</option>
											<option value="2">讲师</option>
											<option value="3">经理</option>
											<option value="4">商家</option>
										</select> 价格: <input id="price1" type="text" class="form-control">
										- <input id="price2" type="text" class="form-control">
										<button id="searchBt" class="layui-btn layui-btn-sm">
											<i class="layui-icon">&#xe615;</i>搜索
										</button>
									</div>
								</form>
							</td>
							<td align="right">
								<button class="layui-btn layui-btn-sm"
									onclick="location.href='addGift.html'" permission="gift:query">
									<i class="layui-icon">&#xe608;</i> 添加
								</button>
							</td>
						</tr>
					</table>
				</div>
			</header>

			<div>
				<div class="widget-body no-padding">
					<table id="dt-table"
						class="table table-striped table-bordered table-hover"
						style="width: 100%">
						<thead>
							<tr>
							</tr>
							<tr>
								<th style="width: 10%">礼包名称</th>
								<th style="width: 5%">礼包价格</th>
								<th style="width: 5%">零钱</th>
								<th style="width: 5%">购买条件</th>
								<th style="width: 5%">购买后身份</th>
								<th style="width: 10%">礼包商品</th>
								<th style="width: 5%">状态</th>
								<th style="width: 8%">创建时间</th>
								<th style="width: 8%">修改时间</th>
								<th style="width: 8%">到期时间</th>
								<th style="width: 10%">操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</body>
</html>

<script type="text/javascript"
	src="../../global/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript"
	src="../../global/js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript"
	src="../../global/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../global/layui/layui.js"></script>
<script type="text/javascript" src="../../global/js/my/permission.js"></script>
<script type="text/javascript">
	var pers = checkPermission();

	var example;

	function init() {
		example = $('#dt-table')
				.DataTable(
						{
							"searching" : false,
							"processing" : false,
							"serverSide" : true,
							"language" : {
								"url" : "/global/js/plugin/datatables/Chinese.lang"
							},
							"ajax" : {
								"url" : "/clyjGift/giftList",
								"type" : "get",
								"data" : function(d) {
									d.giftName = $('#name').val();
									d.buyAfter = $('#after').val();
									d.buyBefor = $('#befor').val();
									d.zkPrice = $('#price1').val();
									d.zkPrice2 = $('#price2').val();
								},
								"error" : function(xhr, textStatus, errorThrown) {
									var msg = xhr.responseText;
									console.log(msg);
									var response = JSON.parse(msg);
									var code = response.code;
									var message = response.message;
									if (code == 400) {
										layer.msg(message);
									} else if (code == 401) {
										localStorage.removeItem("token");
										layer.msg("token过期,请先登录", {
											shift : -1,
											time : 1000
										}, function() {
											location.href = '/login.html';
										});
									} else if (code == 403) {
										console.log("未授权:" + message);
										layer.msg('未授权');
									} else if (code == 500) {
										layer.msg('系统错误:' + message);
									}
								}
							},
							"dom" : "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",
							"columns" : [
									{
										"data" : "giftName",
										"defaultContent" : ""
									},
									{
										"data" : "zkPrice",
										"defaultContent" : ""
									},
									{
										"data" : "pocketMoney",
										"defaultContent" : ""
									},
									{
										"data" : "buyBefor",
										"defaultContent" : "",
										"render" : function(data, type, row) {
											if (data == 0)
												data = "会员";
											if (data == 1)
												data = "导购";
											if (data == 2)
												data = "讲师";
											if (data == 3)
												data = "经理";
											if (data == 4)
												data = "商家";
											return data;
										}
									},
									{
										"data" : "buyAfter",
										"defaultContent" : "",
										"render" : function(data, type, row) {
											if (data == 0)
												data = "会员";
											if (data == 1)
												data = "导购";
											if (data == 2)
												data = "讲师";
											if (data == 3)
												data = "经理";
											if (data == 4)
												data = "商家";
											return data;
										}
									},
									{
										"data" : "goodsName",
										"defaultContent" : "",
										"render" : function(data, type, row) {
											if (data == null || data == "")
												data = "无"
											return data;
										}
									},
									{
										"data" : "status",
										"defaultContent" : "",
										"render" : function(data, type, row) {
											if (data == 1) {
												data = "已下架"
											} else if (data == 0) {
												data = "正常"
											}
											return data;
										}
									},
									{
										"data" : "createTime",
										"defaultContent" : "",
										"render" : function(data) {
											if (data == null || data == "") {
												return data;
											}
											var dateee = new Date(data)
													.toJSON();
											var date = new Date(+new Date(
													dateee) + 8 * 3600 * 1000)
													.toISOString().replace(
															/T/g, ' ').replace(
															/\.[\d]{3}Z/, '')
											data = date
											return data;
										}
									},
									{
										"data" : "updateTime",
										"defaultContent" : "",
										"render" : function(data) {
											if (data == null || data == "") {
												return data;
											}
											var dateee = new Date(data)
													.toJSON();
											var date = new Date(+new Date(
													dateee) + 8 * 3600 * 1000)
													.toISOString().replace(
															/T/g, ' ').replace(
															/\.[\d]{3}Z/, '')
											data = date
											return data;
										}
									},
									{
										"data" : "endTime",
										"defaultContent" : "",
										"render" : function(data) {
											if (data == null || data == "") {
												return data;
											}
											var dateee = new Date(data)
													.toJSON();
											var date = new Date(+new Date(
													dateee) + 8 * 3600 * 1000)
													.toISOString().replace(
															/T/g, ' ').replace(
															/\.[\d]{3}Z/, '')
											data = date
											return data;
										}
									},
									/* {"data": "giftType", "defaultContent": "",
									"render": function (data, type, row) {
									                                           console.log(data)
									                                           if (data == 1) {
									                                                data = "399礼包"
									                                           } else if (data == 2) {
									                                                 data = "998礼包"}
									                                              return data;}},*/

									{
										"data" : "",
										"defaultContent" : "",
										"orderable" : false,
										"render" : function(data, type, row) {
											var id = row['id'];
											var href = "addGift.html?id=" + id;
											var edit = buttonEdit(href,
													"gift:query", pers);
											var del = buttonDel(id,
													"gift:delete", pers);

											return edit + del;
										}
									}, ],
							"order" : [ [ 2, "desc" ] ]
						});
	}

	layui.use('layer', function() {
		var layer = layui.layer;
	});

	function del(id) {
		layer.confirm('确定要删除吗?', {
			btn : [ '确定', '取消' ]
		}, function() {
			$.ajax({
				type : 'post',
				url : '/clyjGift/' + id,
				success : function(data) {
					example.ajax.reload();
					layer.msg("删除成功");
				}
			});

			layer.close(1);
		});
	}

	$("#searchBt").click(function() {
		example.ajax.reload();
	});

	init();
</script>